
<!DOCTYPE html>
<html lang="en" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>SpringBoot工程高级配置 - Hexo</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="Fechin,"> 
    <meta name="description" content="12.2 高级配置12.2.1 临时属性设置
使用jar命令启动SpringBoot工程时可以使用临时属性替换配置文件中的属性


带属性启动SpringBoot

1java -jar sprin,"> 
    <meta name="author" content="John Doe"> 
    <link rel="alternative" href="atom.xml" title="Hexo" type="application/atom+xml"> 
    <link rel="icon" href="/yi-mark-gitee-io/img/favicon.png"> 
    
    
    
    <meta name="twitter:card" content="summary"/>
    <meta name="twitter:title" content="SpringBoot工程高级配置 - Hexo"/>
    <meta name="twitter:description" content="12.2 高级配置12.2.1 临时属性设置
使用jar命令启动SpringBoot工程时可以使用临时属性替换配置文件中的属性


带属性启动SpringBoot

1java -jar sprin,"/>
    
    
    
    
    <meta property="og:site_name" content="Hexo"/>
    <meta property="og:type" content="object"/>
    <meta property="og:title" content="SpringBoot工程高级配置 - Hexo"/>
    <meta property="og:description" content="12.2 高级配置12.2.1 临时属性设置
使用jar命令启动SpringBoot工程时可以使用临时属性替换配置文件中的属性


带属性启动SpringBoot

1java -jar sprin,"/>
    
<link rel="stylesheet" href="/yi-mark-gitee-io/css/diaspora.css">

<meta name="generator" content="Hexo 6.0.0"></head>

<body class="loading">
    <span id="config-title" style="display:none">Hexo</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="iconfont icon-home image-icon" href="javascript:;" data-url="https://yi-mark.gitee.io"></a>
    <div title="播放/暂停" class="iconfont icon-play"></div>
    <h3 class="subtitle">SpringBoot工程高级配置</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="iconfont icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">SpringBoot工程高级配置</h1>
        <div class="stuff">
            <span>二月 08, 2022</span>
            
  <ul class="post-tags-list" itemprop="keywords"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/yi-mark-gitee-io/tags/SpringBoot/" rel="tag">SpringBoot</a></li><li class="post-tags-list-item"><a class="post-tags-list-link" href="/yi-mark-gitee-io/tags/%E8%BF%90%E7%BB%B4/" rel="tag">运维</a></li></ul>


        </div>
        <div class="content markdown">
            <h2 id="12-2-高级配置"><a href="#12-2-高级配置" class="headerlink" title="12.2 高级配置"></a>12.2 高级配置</h2><h3 id="12-2-1-临时属性设置"><a href="#12-2-1-临时属性设置" class="headerlink" title="12.2.1 临时属性设置"></a>12.2.1 临时属性设置</h3><blockquote>
<p>使用jar命令启动SpringBoot工程时可以使用临时属性替换配置文件中的属性</p>
</blockquote>
<ul>
<li>带属性启动SpringBoot</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">java -jar springboot_08_ssmp-0.0.1-SNAPSHOT.jar --server.port=8080</span><br></pre></td></tr></table></figure>

<ul>
<li>携带多个属性启动SpringBoot，属性间使用空格分隔</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">java -jar springboot_08_ssmp-0.0.1-SNAPSHOT.jar --server.port=8080 --spring.datasource.druid.password=123</span><br></pre></td></tr></table></figure>



<p>临时属性必须是当前boot工程支持的属性，否则设置无效</p>
<h3 id="12-2-2临时属性设置（开发环境）"><a href="#12-2-2临时属性设置（开发环境）" class="headerlink" title="12.2.2临时属性设置（开发环境）"></a>12.2.2临时属性设置（开发环境）</h3><ul>
<li>带属性启动SpringBoot程序，为程序添加运行属性</li>
</ul>
<p><img src="https://s2.loli.net/2022/02/08/gsvoS9ENnp2MPwa.png" alt="image-20220208145031857"></p>
<ul>
<li>通过编程形式带参数启动SpringBoot程序，为程序添加启动参数</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">   String[] arg = <span class="keyword">new</span> String[<span class="number">1</span>];</span><br><span class="line">   arg[<span class="number">0</span>] = <span class="string">&quot;--server.port=8082&quot;</span>;</span><br><span class="line">   SpringApplication.run(SSMPApplication.class, arg);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<ul>
<li>不携带参数启动SpringBoot程序</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 可以在启动boot程序时断开外部临时配置对应的入口，也就是去掉读取外部参数的形参</span></span><br><span class="line">    SpringApplication.run(SSMPApplication.class);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-2-3-配置文件分类"><a href="#12-2-3-配置文件分类" class="headerlink" title="12.2.3 配置文件分类"></a>12.2.3 配置文件分类</h3><blockquote>
<p>SpringBoot中4级配置文件</p>
</blockquote>
<ul>
<li>1级：file:config&#x2F;application.yml [最高]</li>
<li>2级：file:application.yml</li>
<li>3级：classpath:config&#x2F;application.yml</li>
<li>4级：classpath:application.yml [最低]</li>
</ul>
<blockquote>
<p>作用</p>
</blockquote>
<ul>
<li>1级和2级留作系统打包设置通用属性，1级常用于运维经理进行线上整体项目部署方案调控</li>
<li>3级和4级用于系统开发阶段设置通用属性，3级常用与项目经理进行整体项目属性调控</li>
</ul>
<blockquote>
<p>总结</p>
</blockquote>
<ul>
<li><p>配置文件分为4种：</p>
<ul>
<li>项目类路径配置文件：服务于开发人员本机开发与测试</li>
<li>项目类路径config目录中配置文件：服务于项目经理整体调控</li>
<li>工程路径配置文件：服务于运维人员配置涉密线上环境</li>
<li>工程路径config目录中配置文件：服务于运维经理整体调控</li>
</ul>
</li>
<li><p>多层级配置文件间的属性采用叠加并覆盖的形式作用于程序</p>
</li>
</ul>
<h3 id="12-2-4-自定义配置文件"><a href="#12-2-4-自定义配置文件" class="headerlink" title="12.2.4 自定义配置文件"></a>12.2.4 自定义配置文件</h3><ul>
<li>通过启动参数加载配置文件（无需书写配置文件扩展名）</li>
</ul>
<p><img src="https://s2.loli.net/2022/02/08/TXQLsnbEBiVy5mA.png" alt="image-20220208145527052"></p>
<ul>
<li>通过启动参数加载指定文件路径下的配置文件（支持多配置文件，后面的能覆盖的前面的）</li>
</ul>
<p><img src="https://s2.loli.net/2022/02/08/EjaeNf5A3gYDwLl.png" alt="image-20220208145603733"></p>
<blockquote>
<p>注意事项：</p>
</blockquote>
<ul>
<li><p>.yml和.properties都有效</p>
</li>
<li><p>多配置文件常用于将配置进行分类，进行独立管理，或将可选配置单独制作便于上线维护更新</p>
</li>
</ul>
<p>重要说明：</p>
<ul>
<li><p>单服务器项目：使用自定义配置文件需求极低</p>
</li>
<li><p>多服务器项目：使用自定义配置文件需求较高，将所有配置文件放置在一个目录中，统一管理</p>
</li>
<li><p>基于SpringCloud技术，所有服务器将不再设置配置文件，而是通过配置中心进行设定，动态加载配置信息</p>
</li>
</ul>

            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls" data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
                <ul id="audio-list" style="display:none">
                    
                        
                            <li title="0" data-url="http://link.hhtjim.com/163/425570952.mp3"></li>
                        
                    
                        
                            <li title="1" data-url="http://link.hhtjim.com/163/425570952.mp3"></li>
                        
                    
                </ul>
            
        </div>
        
    <div id="gitalk-container" class="comment link"
		data-enable="false"
        data-ae="false"
        data-ci=""
        data-cs=""
        data-r=""
        data-o=""
        data-a=""
        data-d="false"
    >查看评论</div>


    </div>
    
</div>


    </div>
</div>
</body>


<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="/yi-mark-gitee-io/js/plugin.js"></script>
<script src="/yi-mark-gitee-io/js/typed.js"></script>
<script src="/yi-mark-gitee-io/js/diaspora.js"></script>


<link rel="stylesheet" href="/yi-mark-gitee-io/photoswipe/photoswipe.css">
<link rel="stylesheet" href="/yi-mark-gitee-io/photoswipe/default-skin/default-skin.css">


<script src="/yi-mark-gitee-io/photoswipe/photoswipe.min.js"></script>
<script src="/yi-mark-gitee-io/photoswipe/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>






</html>
